package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Guard;
import cn.wolfcode.crm.domain.OutPay;
import cn.wolfcode.crm.query.OutPayQueryObject;
import cn.wolfcode.crm.service.IGuardService;
import cn.wolfcode.crm.service.IInPayService;
import cn.wolfcode.crm.service.IOutPayService;
import cn.wolfcode.crm.util.JsonResult;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("outpay")
public class OutPayController {

    @Autowired
    private IOutPayService outPayService;
    @Autowired
    private IInPayService inPayService;

    @RequestMapping("view")
    public String view() throws Exception{
        return "outpay/outpay";
    }

    @ResponseBody
    @RequestMapping("update")
    public JsonResult update(OutPay entity){
        JsonResult jsonResult = new JsonResult();
        try{
            outPayService.update(entity);
            inPayService.insert(entity.getId());

        }catch (Exception e){
            e.printStackTrace();
            jsonResult.mark("保存失败");
        }
        return jsonResult;
    }

    @RequestMapping("list")
    @ResponseBody
    public Object list(OutPayQueryObject qo) throws Exception{
        return JSON.toJSON(outPayService.query(qo));
    }

}
